<%--
  Created by IntelliJ IDEA.
  User: zuxia
  Date: 2018/7/18
  Time: 11:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>菜品类别</title>
    <link rel="stylesheet" href="../css/admin.css" />
    <link rel="stylesheet" href="../css/amazeui.min.css" />
    <link rel="stylesheet" href="../css/layui.css" />
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">菜品类别管理</strong><small></small></div>
    </div>

    <hr>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default">
                        <a href="javascript:void(0)"  onclick="addFoodType('添加菜品类型',1)">新增</a>
                    </button>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">

        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">

                <input type="text" id="sousuo" class="am-form-field" placeholder="请输入菜品类型">
                <span class="am-input-group-btn">
								<button class="am-btn am-btn-default" id="sousuobt" type="button">搜索</button>
				        	</span>

            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">ID</th>
                        <th class="table-title">菜品类别</th>
                        <th class="table-set">操作</th>
                    </tr>
                    </thead>
                    <tbody id="table_tbody">

                    </tbody>
                </table>
                <hr>
            </form>
        </div>

    </div>
</div>
</body>

<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../myplugs/js/plugs.js"></script>
<script type="text/javascript" src="../js/layui.all.js"></script>
<script type="text/javascript" src="../js/Popup.js"></script>

<script type="text/javascript" src="../js/jquery-1.4.1.js"></script>
<script type="text/javascript">
    //添加ajax分页
    $().ready(function() {
        //执行一次
        loaddata("","","");

        //搜索单击事件
        $("#sousuobt").click(function(){
            var keyword = $("#sousuo").val();
            //console.log(keyword);
            // 加载数据
            loaddata(keyword,"","");
        });
        //详情按钮单击事件
        // $("#showorder").live("click",function(){
        //     var orderid=$(this).parent().parent().prevAll().last().text();
        //     console.log(orderid+"111");
        //     window.location.href="/fullboy/skipvalue.action?skipvalue="+orderid.trim();
        // });
        //删除按钮单击事件
        $("#deletefoodtype").live("click",function(){
            var typeid=$(this).parent().parent().parent().prevAll().last().text();
            deletetype(typeid);
            loaddata("","","");
        });

        $(".prev").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算上一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            if(pageNo == undefined || pageNo <= 1){
                pageNo = 1;
            }else{
                pageNo = pageNo -1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".next").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            var totalNo = $(".total_num").text();
            totalNo = parseInt(totalNo);
            if(pageNo == undefined){
                pageNo = 1;
            }else if(pageNo >= totalNo){
                pageNo =totalNo;
            }else{
                pageNo = pageNo + 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".first").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = 1;
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".last").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".total_num").text();
            if(pageNo == undefined){
                pageNo = 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

    });

    //删除事件
    function deletetype(typeid) {
        $.ajax({
            url:"/fullboy/deleteType.action",
            data:{"typeid":typeid},
            type: "POST",
            cache: false,
        });
    }
    //ajax加载数据方法
    function loaddata(keyword,pageno,pagesize) {
        $("#table_tbody").empty();
        $.ajax({
            url:"/fullboy/queryFoodType.action",
            //querydetailsorderid
            data:{"keyword":keyword,"pageno":pageno,"pagesize":pagesize},
            type: "POST",
            cache: false,
            dataType: "json",
            success:function(data){
                console.log(data);
                if(data.success){
                    var foodtypelist=data.data.list;
                    for(var i=0;i<foodtypelist.length;i++){
                        var typeslistobj=foodtypelist[i];
                        $("#table_tbody").append("<tr>"+
                        "<td>"+typeslistobj.dTypeId+"</td>"+
                        "<td>"+
                        "<a href='#'>"+typeslistobj.dTypeName+"</a>"+
                        "</td>"+
                        "<td>"+
                        "<div class='am-btn-toolbar'>"+
                        "<div class='am-btn-group am-btn-group-xs'>"+
                        "<button class='am-btn am-btn-default am-btn-xs am-text-secondary'>"+
                        "<span class='am-icon-pencil-square-o'></span>"+
                        "<a href='javascript:void(0)'  onclick=\"uplFoodType('修改菜品类型',1)\">编辑 </a>"+
                        "</button>"+
                        "<button id='deletefoodtype' class='am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only'>"+
                        "<span class='am-icon-trash-o'></span>"+
                        "<a href='#' style='color: red;'>删除</a>"+
                        "</button>"+
                        "</div>"+
                        "</div>"+
                        "</td>"+
                        "</tr>");
                    }

                    $("#table_tbody").append("<tr style='border-bottom:1px solid #AAAAAA;height: 50px;text-align:center;'><td colspan='3'><div id='page_div'><span class='current_num'>" +
                        data.data.pageNo+"</span>/<span class='total_num'>"+data.data.pageCount+"</span>页   每页"+data.data.pageSize+"条  共"+
                        data.data.totalNumber+"条数据 "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='prev'>上一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='next'>下一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='first'>首页</a> "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='last'>尾页</a></div></td></tr>");
                }else{
                    $("#table_tbody").append("<tr><td colspan='3' style='color:#2530ff'>"+data.errorMessage+"</td></tr>");
                }
            }
        });
    }


</script>
</html>